package com.sh.双指针;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 盛最多水的容器 {
    public static void main(String[] args) {
        int[] ints = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int i = maxArea(ints);
        System.out.println(i);
    }

    public static int maxArea(int[] height) {
        int res = 0;
        int left = 0, right = height.length - 1;
        res = Math.min(height[left], height[right]) * (right - left);
        while (left < right) {
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
            res = Math.max(res, Math.min(height[left], height[right]) * (right - left));
        }
        return res;
    }
}

